#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 1010;
int n, m, p;
int map[N][N], c[N], q[N][N], x[N][N], l[N], r[N], add[N], f[N];

inline int getid(int i, int j) { return ((j - i) % n + n) % n; }

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("P1070 道路游戏.in", "r", stdin);
  freopen("P1070 道路游戏.out", "w", stdout);
#endif
#endif

  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &map[j][i]);
      map[j][i] += map[j - 1][i - 1];
    }
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    q[i][++r[i]] = -c[i], ++l[i];
  }
  memset(f, -0x3f, sizeof(f));
  f[0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0, id; j < n; j++) {
      id = getid(i, j);
      while (l[id] <= r[id] && x[id][l[id]] + p < i) l[id]++;
      if (!j) add[id] += map[i][n];
      if (l[id] <= r[id]) {
        f[i] = std::max(f[i], q[id][l[id]] + add[id] + map[i][j]);
      }
    }
    for (int j = 0, id; j < n; j++) {
      int tmp = f[i] - add[id = getid(i, j)] - map[i][j] - c[j];
      while (l[id] <= r[id] && q[id][r[id]] <= tmp) r[id]--;
      x[id][++r[id]] = i;
      q[id][r[id]] = tmp;
    }
  }
  printf("%d\n", f[m]);
  return 0;
}